<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <link href="/assets/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/assets/bootstrap/js/jquery-confirm/jquery-confirm.min.css" rel="stylesheet">
    <link href="/assets/bootstrap/css/style.min.css" rel="stylesheet">
</head>

<body>
<div class="container-fluid p-t-15">
    <div class="row">
        <div class="col-lg-6">
            <div class="card">
                <header class="card-header">
                    <div class="card-title"> 生成控制器方法</div>
                </header>
                <div class="card-body">
                    <div class="form-group">
                        <label for="handlerName">API handler 名称，例如：<code>user</code>，<small>user 为 internal/api
                            目录下的文件夹名称</small></label>
                        <input type="text" class="form-control" id="handlerName" placeholder="请输入 handler 名称">
                    </div>

                    <p>
                        <button type="button" id="btnOk" class="btn btn-primary">确认</button>
                        <button type="button" id="btnLoading" class="btn btn-primary" disabled style="display: none">
                            <span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
                            执行中...
                        </button>
                    </p>

                </div>
            </div>
        </div>

        <div class="col-lg-6">
            <div class="card">
                <header class="card-header">
                    <div class="card-title">执行结果</div>
                </header>
                <div class="card-body">
                    <pre id="resultDiv"></pre>
                </div>
            </div>
        </div>

    </div>
</div>

<script type="text/javascript" src="/assets/bootstrap/js/jquery.min.js"></script>
<script type="text/javascript" src="/assets/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/assets/bootstrap/js/jquery-confirm/jquery-confirm.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#btnOk").click(function () {
            var handlerName = $("#handlerName").val();
            if (!handlerName) {
                $.alert({
                    title: '温馨提示',
                    icon: 'mdi mdi-alert',
                    type: 'orange',
                    content: '请输入 handler 名称。',
                });
                return false;
            }

            $("#resultDiv").text("");
            $(this).hide();
            $("#btnLoading").show();

            $.post("/generator/handler/execute", {name: handlerName}, function (data) {
                $("#resultDiv").text(data);
                $("#btnLoading").hide();
                $("#btnOk").show();
            })

        })
    })
</script>
<div style="display:none">
    <script type="text/javascript">document.write(unescape("%3Cspan id='cnzz_stat_icon_1279911342'%3E%3C/span%3E%3Cscript src='https://v1.cnzz.com/z_stat.php%3Fid%3D1279911342%26' type='text/javascript'%3E%3C/script%3E"));</script>
</div>
</body>
</html>
